home *** CD-ROM | disk | FTP | other *** search
/ Computer Shopper 125 / Computer Shopper CD-ROM Issue 125 (1998-07)(Dennis Publishing).iso / Business / Dazzler / DAZZLER.Z / CListBoxResponse.class (.txt) < prev    next >
Encoding:
Java Class File  |  1997-11-26  |  4.6 KB  |  205 lines

  1. import java.awt.Color;
  2. import java.awt.Graphics;
  3. import java.awt.Point;
  4. import java.awt.Rectangle;
  5. import java.io.DataInputStream;
  6.  
  7. public class CListBoxResponse extends CDisplayResponse {
  8.    private int m_nFlags = 17;
  9.    private Color m_rgbFg = new Color(0, 0, 0);
  10.    private Color m_rgbBg = new Color(255, 255, 255);
  11.    private String m_strFillWith = "";
  12.    private String m_strSelect = "";
  13.    private String m_strDelimiter = "";
  14.    private char m_nVariableID = 0;
  15.    private CFontObject m_clsFontObject = new CFontObject();
  16.    private String m_strList = "";
  17.    private CComboBox m_ComboBox = null;
  18.    private CListBox m_ListBox = null;
  19.  
  20.    boolean LoadFromFile(DataInputStream var1) {
  21.       this.m_nVariableID = (char)FileLoad.ReadCPlusInt(var1);
  22.       this.m_nFlags = FileLoad.ReadCPlusInt(var1);
  23.       this.m_rgbFg = FileLoad.ReadColor(var1);
  24.       this.m_rgbBg = FileLoad.ReadColor(var1);
  25.       this.m_strFillWith = FileLoad.ReadCString(var1);
  26.       this.m_strSelect = FileLoad.ReadCString(var1);
  27.       this.m_strDelimiter = FileLoad.ReadCString(var1);
  28.       this.m_clsFontObject.LoadFromFile(var1);
  29.       return super.LoadFromFile(var1);
  30.    }
  31.  
  32.    public void DoEntryResponse() {
  33.       this.DoResponse(0);
  34.    }
  35.  
  36.    public CListBoxResponse() {
  37.       super(45);
  38.    }
  39.  
  40.    CResponseReturn DoResponse(int var1) {
  41.       CResponseReturn var2 = new CResponseReturn(0, var1);
  42.       if (this.m_nVariableID != 0) {
  43.          CVariable var3 = Utils.SearchAllVariables(this.m_nVariableID);
  44.          if (var3 != null) {
  45.             String var4 = "";
  46.             if (this.m_ListBox != null && (this.m_nFlags & 1) != 0) {
  47.                if ((this.m_nFlags & 8) != 0) {
  48.                   String var5 = this.m_strDelimiter.length() > 0 ? this.m_strDelimiter : "\r\n";
  49.  
  50.                   for(int var7 = 0; var7 < this.m_ListBox.GetSelCount(); ++var7) {
  51.                      String var6 = this.m_ListBox.GetSel(var7);
  52.                      if (var4.length() > 0) {
  53.                         var4 = var4 + var5;
  54.                      }
  55.  
  56.                      var4 = var4 + var6;
  57.                   }
  58.                } else {
  59.                   var4 = this.m_ListBox.GetSel();
  60.                }
  61.             } else if (this.m_ComboBox != null && (this.m_nFlags & 2) != 0) {
  62.                var4 = this.m_ComboBox.GetSel();
  63.             }
  64.  
  65.             System.out.println("Selection = " + var4);
  66.             if (var4.length() > 0) {
  67.                switch (var3.GetType()) {
  68.                   case 256:
  69.                      var3.SetValue(var4);
  70.                      break;
  71.                   case 512:
  72.                      try {
  73.                         var3.SetValue(Double.valueOf(var4));
  74.                      } catch (NumberFormatException var9) {
  75.                         var3.SetValue((double)0.0F);
  76.                      }
  77.                      break;
  78.                   case 1024:
  79.                      try {
  80.                         var3.SetValue(Long.valueOf(var4));
  81.                      } catch (NumberFormatException var8) {
  82.                         var3.SetValue(0L);
  83.                      }
  84.                }
  85.             } else {
  86.                var3.Reset();
  87.             }
  88.          }
  89.       }
  90.  
  91.       return var2;
  92.    }
  93.  
  94.    public boolean OnMouseClick(int var1, int var2, Point var3, int var4, CRect var5) {
  95.       if (var4 == 7) {
  96.          if ((this.m_nFlags & 1) != 0 && this.m_ListBox != null) {
  97.             if (var1 == 2022 && ((CDisplayResponse)this).HitTest(var3)) {
  98.                this.m_ListBox.ProcessMouseDown(var3);
  99.             } else if (var1 == 2023 && this.m_ListBox.HasFocus()) {
  100.                this.m_ListBox.ProcessMouseUp(var3);
  101.             }
  102.          } else if ((this.m_nFlags & 2) != 0 && this.m_ComboBox != null) {
  103.             if (var1 != 2022 || !((CDisplayResponse)this).HitTest(var3) && !this.m_ComboBox.ListVisible()) {
  104.                if (var1 == 2023 && this.m_ComboBox.HasFocus()) {
  105.                   this.m_ComboBox.ProcessMouseUp(var3);
  106.                }
  107.             } else {
  108.                this.m_ComboBox.ProcessMouseDown(var3);
  109.             }
  110.          }
  111.       }
  112.  
  113.       return false;
  114.    }
  115.  
  116.    public boolean SetResponse() {
  117.       if (!((CDisplayResponse)this).GetActualRect().isEmpty()) {
  118.          boolean var1 = false;
  119.          CRect var2 = new CRect(((CDisplayResponse)this).GetActualRect());
  120.          if ((this.m_nFlags & 1) != 0) {
  121.             if (this.m_ListBox == null) {
  122.                this.m_ListBox = new CListBox(this.m_nFlags, ((CDisplayResponse)this).GetActualRect());
  123.                this.m_ListBox.SetFont(this.m_clsFontObject.GetFont());
  124.                this.m_ListBox.SetBgColour(this.m_rgbBg);
  125.                this.m_ListBox.SetFgColour(this.m_rgbFg);
  126.             } else if (!((Rectangle)var2).equals(((CDisplayResponse)this).GetDrawRect())) {
  127.                this.m_ListBox.SetRect(var2);
  128.             }
  129.  
  130.             String var5 = Utils.InsertVariablesInString(this.m_strFillWith);
  131.             if (var5.length() > 0 && !this.m_strList.equals(var5)) {
  132.                this.m_strList = var5;
  133.                this.m_ListBox.FillListBox(var5, this.m_strDelimiter);
  134.                var1 = true;
  135.             }
  136.  
  137.             String var6 = Utils.InsertVariablesInString(this.m_strSelect);
  138.             if (var6.length() > 0) {
  139.                this.m_ListBox.SetSelections(var6, this.m_strDelimiter);
  140.                var1 = true;
  141.             }
  142.          } else if ((this.m_nFlags & 2) != 0) {
  143.             if (this.m_ComboBox == null) {
  144.                this.m_ComboBox = new CComboBox(this.m_nFlags, ((CDisplayResponse)this).GetActualRect());
  145.                this.m_ComboBox.SetFont(this.m_clsFontObject.GetFont());
  146.                this.m_ComboBox.SetBgColour(this.m_rgbBg);
  147.                this.m_ComboBox.SetFgColour(this.m_rgbFg);
  148.             } else if (!((Rectangle)var2).equals(((CDisplayResponse)this).GetDrawRect())) {
  149.                this.m_ComboBox.SetRect(var2);
  150.             }
  151.  
  152.             String var3 = Utils.InsertVariablesInString(this.m_strFillWith);
  153.             if (var3.length() > 0 && !this.m_strList.equals(var3)) {
  154.                this.m_strList = var3;
  155.                this.m_ComboBox.FillListBox(var3, this.m_strDelimiter);
  156.             }
  157.  
  158.             String var4 = Utils.InsertVariablesInString(this.m_strSelect);
  159.             if (!this.m_ComboBox.SelectionValid() || var4.length() > 0 && !var4.equals(this.m_ComboBox.GetSel())) {
  160.                this.m_ComboBox.SetSelections(var4, this.m_strDelimiter);
  161.                var1 = true;
  162.             }
  163.          }
  164.  
  165.          if (!((Rectangle)var2).equals(((CDisplayResponse)this).GetDrawRect())) {
  166.             if (!((CDisplayResponse)this).GetDrawRect().isEmpty()) {
  167.                Globals.thePresView.InvalidateOffScreenRect(((CDisplayResponse)this).GetDrawRect());
  168.             }
  169.  
  170.             ((CDisplayResponse)this).SetDrawRect(var2);
  171.             var1 = true;
  172.          }
  173.  
  174.          Globals.thePresView.AddDrawObject((CIconObject)this, 1024, var1);
  175.       }
  176.  
  177.       return true;
  178.    }
  179.  
  180.    public boolean OnMouseMove(int var1, Point var2, int var3, CRect var4) {
  181.       if (var3 == 7) {
  182.          if (this.m_ListBox != null && (this.m_nFlags & 1) != 0 && (this.m_nFlags & 8) == 0) {
  183.             if (this.m_ListBox.HasFocus()) {
  184.                this.m_ListBox.ProcessMouseMove(var2);
  185.             }
  186.          } else if (this.m_ComboBox != null && (this.m_nFlags & 2) != 0 && this.m_ComboBox.ListVisible()) {
  187.             this.m_ComboBox.ProcessMouseMove(var2);
  188.          }
  189.       }
  190.  
  191.       return false;
  192.    }
  193.  
  194.    public void DrawObject(Graphics var1, int var2, CRect var3) {
  195.       if (this.m_ListBox != null) {
  196.          this.m_ListBox.DrawControl(var1, var3);
  197.       } else {
  198.          if (this.m_ComboBox != null) {
  199.             this.m_ComboBox.DrawControl(var1, var3);
  200.          }
  201.  
  202.       }
  203.    }
  204. }
  205.